package com.service.atf.base.model;


import com.service.atf.base.core.ByteConvertion;
import com.service.atf.base.exception.TFException;
import com.service.atf.base.utils.ATFConstants;
import com.service.atf.base.utils.ATFLogger;
import com.luotao.devp.base.utils.ByteUtil;

/**
 * User: luotao
 * Date: 12-2-23
 * Time: 11:34:00
 */
public class TFTrade extends BaseFlow implements ByteConvertion {
    //������Ϸ����	int 		�ͻ���
    private int gamecode;

    //��Ӫ�̱�ʶ	Byte		NCP
    private byte channelType;
    //�ֻ��ն�����	char(20)		�ֻ�ͻ���
    private String mobileOSType = "";

    //Ʊ�����ݴ�С	Byte
    private short ticketLen;
    //Ʊ������	Char(256)		ATF
    private byte[] ticketContent = new byte[0];
    //Ͷע����	short		�ֻ�ͻ���
    private short multiple;
    //�Ƿ��	Byte		ATF

    //Ͷע�ڴ�	Char(12)		�ֻ�ͻ���
    private String peroid = "";
    //Ʊ����ϢժҪ	Char(16)		ATF
    private String ticketMemo = "";
    //�Զ��ο�ʱ��	int	2000�굽���ڵĺ�������ȡ��2λ	MP
    private int autoAwardDate;
    //�ҽ���ֹʱ��	int	2000�굽���ڵĺ�������ȡ��2λ	MP
    private int endAwardDate;

    private long tradeMoney;

    private String ticketId;

    private int awardMoney;

    private byte isBigWin;

    private byte timeout;

    private int autoBingoMoney;

    public TFTrade() {
        setType((byte) '1');
        setTradeType((byte) '1');
    }

    public int getAutoBingoMoney() {
        return autoBingoMoney;
    }

    public void setAutoBingoMoney(int autoBingoMoney) {
        this.autoBingoMoney = autoBingoMoney;
    }

    public byte getTimeout() {
        return timeout;
    }

    public void setTimeout(byte timeout) {
        this.timeout = timeout;
    }

    public String getTicketId() {
        return ticketId;
    }

    public void setTicketId(String ticketId) {
        this.ticketId = ticketId;
    }

    public int getAwardMoney() {
        return awardMoney;
    }

    public void setAwardMoney(int awardMoney) {
        this.awardMoney = awardMoney;
    }

    public long getTradeMoney() {
        return tradeMoney;
    }

    public void setTradeMoney(long tradeMoney) {
        this.tradeMoney = tradeMoney;
    }

    public int getGamecode() {
        return gamecode;
    }

    public void setGamecode(int gamecode) {
        this.gamecode = gamecode;
    }

    public byte getChannelType() {
        return channelType;
    }

    public void setChannelType(byte channelType) {
        this.channelType = channelType;
    }

    public String getMobileOSType() {
        return mobileOSType;
    }

    public void setMobileOSType(String mobileOSType) {
        this.mobileOSType = mobileOSType;
    }


    public short getTicketLen() {
        return ticketLen;
    }

    public void setTicketLen(short ticketLen) {
        this.ticketLen = ticketLen;
    }

    public byte[] getTicketContent() {
        return ticketContent;
    }

    public void setTicketContent(byte[] paramContent) {
        this.ticketContent = new byte[paramContent.length];
        System.arraycopy(paramContent, 0, this.ticketContent, 0, paramContent.length);
    }

    public short getMultiple() {
        return multiple;
    }

    public void setMultiple(short multiple) {
        this.multiple = multiple;
    }


    public String getPeroid() {
        return peroid;
    }

    public void setPeroid(String peroid) {
        this.peroid = peroid;
    }

    public String getTicketMemo() {
        return ticketMemo;
    }

    public void setTicketMemo(String ticketMemo) {
        this.ticketMemo = ticketMemo;
    }

    public int getAutoAwardDate() {
        return autoAwardDate;
    }

    public void setAutoAwardDate(int autoAwardDate) {
        this.autoAwardDate = autoAwardDate;
    }

    public int getEndAwardDate() {
        return endAwardDate;
    }

    public void setEndAwardDate(int endAwardDate) {
        this.endAwardDate = endAwardDate;
    }

    @Override
    public ByteConvertion byte2Object(byte[] src) {
        byte2ObjectFlow(src);
        setGamecode(ByteUtil.readInt(src, LEN_ALL));

        setChannelType((byte) ByteUtil.read(src, LEN_ALL + 4));
        setMobileOSType(ByteUtil.readString(src, LEN_ALL + 5, 20));
        setMultiple((short) ByteUtil.readShort(src, LEN_ALL + 25));
        setPeroid(ByteUtil.readString(src, LEN_ALL + 27, 12));
        setTicketMemo(ByteUtil.readString(src, LEN_ALL + 39, 16));
        setAutoAwardDate(ByteUtil.readInt(src, LEN_ALL + 55));
        setEndAwardDate(ByteUtil.readInt(src, LEN_ALL + 59));
        ticketId = ByteUtil.readString(src, LEN_ALL + 63, 20);
        isBigWin = (byte) ByteUtil.read(src, LEN_ALL + 83);
        awardMoney = ByteUtil.readInt(src, LEN_ALL + 84);
        timeout = (byte) ByteUtil.read(src, LEN_ALL + 88);
        ticketLen = (short) ByteUtil.read(src, LEN_ALL + 89);
        ticketContent = new byte[ticketLen];
        System.arraycopy(src, LEN_ALL + 90, ticketContent, 0, ticketLen);
        return this;
    }

    @Override
    public byte[] object2Byte() {
        try {
            byte[] flow = object2ByteFlow();
            short ticketLen = getTicketLen();
            byte[] result = new byte[LEN_ALL + 90 + ticketLen];
            System.arraycopy(flow, 0, result, 0, flow.length);
            ByteUtil.writeInt(result, LEN_ALL, getGamecode());

            ByteUtil.write(result, LEN_ALL + 4, getChannelType());
            ByteUtil.writeString(result, LEN_ALL + 5, getMobileOSType(), 20);
            ByteUtil.writeShort(result, LEN_ALL + 25, getMultiple());
            ByteUtil.writeString(result, LEN_ALL + 27, getPeroid(), 12);
            ByteUtil.writeString(result, LEN_ALL + 39, getTicketMemo(), 16);
            ByteUtil.writeInt(result, LEN_ALL + 55, getAutoAwardDate());
            ByteUtil.writeInt(result, LEN_ALL + 59, getEndAwardDate());
            ByteUtil.writeString(result, LEN_ALL + 63, ticketId, 20);
            ByteUtil.write(result, LEN_ALL + 83, isBigWin);
            ByteUtil.writeInt(result, LEN_ALL + 84, awardMoney);
            ByteUtil.write(result, LEN_ALL + 88, timeout);
            ByteUtil.write(result, LEN_ALL + 89, (byte) ticketLen);
//      ByteUtil.writeString(result, LEN_ALL+93, getTicketContent(), ticketLen);
            System.arraycopy(ticketContent, 0, result, LEN_ALL + 90, ticketLen);
            return result;
        } catch (Exception e) {
            String msg = getClass().getName() + "����ת����byte������� : " + e.toString();
            ATFLogger.syserr(msg);
            throw new TFException(ATFConstants.ATF_BYTE_CONV_ERR, msg);
        }
    }

    public void showInfo() {
        ATFLogger.sysdebug("bussTrade.getType() : " + getType());
        ATFLogger.sysdebug("bussTrade.getTradeType() : " + getTradeType());
        ATFLogger.sysdebug("bussTrade.getThreadid() : " + getThreadid());

        ATFLogger.sysdebug("bussTrade.getFlowId() : " + getFlowId());
        ATFLogger.sysdebug("bussTrade.getCustomerCode() : " + getCustomerCode());
        ATFLogger.sysdebug("bussTrade.getSendType() : " + getSendType());
        ATFLogger.sysdebug("bussTrade.getTradeMoney() : " + getTradeMoney());
        ATFLogger.sysdebug("bussTrade.getCreateDate() : " + getCreateDate());
        ATFLogger.sysdebug("bussTrade.getConfirmDate() : " + getConfirmDate());
        ATFLogger.sysdebug("bussTrade.getMappedFlowId() : " + getMappedFlowId());
        ATFLogger.sysdebug("bussTrade.getGamecode() : " + getGamecode());

        ATFLogger.sysdebug("bussTrade.getChannelType() : " + getChannelType());
        ATFLogger.sysdebug("bussTrade.getMobileOSType() : " + getMobileOSType());
        ATFLogger.sysdebug("bussTrade.getMultiple() : " + getMultiple());
        ATFLogger.sysdebug("bussTrade.getPeroid() : " + getPeroid());
        ATFLogger.sysdebug("bussTrade.getAutoAwardDate() : " + getAutoAwardDate());
        ATFLogger.sysdebug("bussTrade.getEndAwardDate() : " + getEndAwardDate());
        ATFLogger.sysdebug("getTicketLen : " + getTicketLen());
        ATFLogger.sysdebug("getTicketContent : " + getTicketContent());
        if (getTicketContent() != null) {
            ATFLogger.sysdebug("getTicketContentLEn : " + getTicketContent().length);
        }
        ATFLogger.sysdebug("getTicketMemo : " + getTicketMemo());
        ATFLogger.sysdebug("getAwardMoney : " + getAwardMoney());
    }

    public byte getBigWin() {
        return isBigWin;
    }

    public void setBigWin(byte bigWin) {
        isBigWin = bigWin;
    }
}
